AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")

function ENT:SpawnFunction(ply, tr) -- Spawn function needed to make it appear on the spawn menu
	if (!tr.HitWorld) then return end
 
	local ent = ents.Create("weed_npc") -- Create the entity
	ent:SetPos(tr.HitPos + Vector(0, 0, 5)) -- Set it to spawn 50 units over the spot you aim at when spawning it
	ent:Spawn() -- Spawn it 
		
		return ent -- You need to return the entity to make it work
end

function ENT:Initialize()
	self:SetModel("models/Humans/Group02/male_07.mdl")
	self:SetHullType(HULL_HUMAN);
   	self:SetHullSizeNormal();
   	self:SetSolid( SOLID_BBOX )
   	self:SetMoveType( MOVETYPE_NONE )
	self:SetUseType( SIMPLE_USE )
	self:CapabilitiesAdd( CAP_ANIMATEDFACE || CAP_TURN_HEAD )
	self:DropToFloor()

	MakeNPCText(self.Entity, "Pot Head")
end

function ENT:AcceptInput(input, activator, caller, data)
	local payout=0
	local i = 1
	if activator:GetTable().Inventory then
		local bread = #activator:GetTable().Inventory
		self.Hash=false

		while i < bread+1 do
		    if activator:GetTable().Inventory[i].class == "durgz_weed" then
		   		payout = payout + 100
		    	table.remove(activator:GetTable().Inventory, i)
		    	bread = bread-1
			elseif activator:GetTable().Inventory[i].class == "hash_ball" then
				payout = payout + 2000
		    	table.remove(activator:GetTable().Inventory, i)
		    	self.Hash = true
		    	bread = bread-1
			else
				i=i+1
			end
		end
	end
	
	if payout != 0 then
		activator:AddMoney(payout)
		if !self.Hash then
			GAMEMODE:Notify(activator, 2, 4, "Here's " .. CUR .. payout .. ", it better be dat loud!")
		else
			GAMEMODE:Notify(activator, 2, 4, "Oh shit!  Hash!?  Here's " .. CUR .. payout .. ", I'mma smoke gooood tonight!")
		end
	else
		GAMEMODE:Notify(activator, 1, 4, "What, you sayin you all out?  Whatever man, I got other dealers.")
	end
	saveInventory(activator)
end